{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">

                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" id="public_name" class="layui-input search" name="public_name" placeholder="公开课名称"/>
                        </div>

                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" id="user_username" class="layui-input search" name="user_username" placeholder="老师昵称"/>
                        </div>

                        <div class="layui-input-inline layui-form">
                            <select name="public_type" id="public_type" lay-search="" class="layui-input">
                                <option value="">不限费用类型</option>
                                <option value="1">免费</option>
                                <option value="2">付费</option>
                            </select>
                        </div>

                        <div class="layui-input-inline layui-form">
                            <select name="public_subject" id="public_subject" lay-search="" class="layui-input">
                                <option value="">不限课程类型</option>
                                <option value="1">语文</option>
                                <option value="2">数学</option>
                                <option value="3">英语</option>
                                <option value="4">政治</option>
                                <option value="5">地理</option>
                                <option value="6">物理</option>
                                <option value="7">化学</option>
                                <option value="8">生物</option>
                                <option value="9">历史</option>
                                <option value="11">计算机</option>
                                <option value="10">填志愿</option>
                            </select>
                        </div>

                        <div class="layui-input-inline layui-form">
                            <select name="is_hot" id="is_hot" lay-search="" class="layui-input">
                                <option value="">全部</option>
                                <option value="1">精品公开课</option>
                                <option value="2">非精品公开课</option>
                            </select>
                        </div>

                        <div class="layui-input-inline layui-form" style="margin-top: 5px">
                            <select name="public_grade" id="public_grade" lay-search="" class="layui-input">
                                <option value="">全部年级</option>
                                <option value="1">一年级</option>
                                <option value="2">二年级</option>
                                <option value="3">三年级</option>
                                <option value="4">四年级</option>
                                <option value="5">五年级</option>
                                <option value="6">六年级</option>
                                <option value="7">七年级</option>
                                <option value="8">八年级</option>
                                <option value="9">九年级</option>
                                <option value="10">十年级</option>
                                <option value="11">十一年级</option>
                                <option value="12">十二年级</option>
                            </select>
                        </div>

                        <div class="layui-input-inline layui-form" style="margin-top: 5px">
                            <select name="public_from" id="public_from" lay-search="" class="layui-input">
                                <option value="">不限发布端</option>
                                <option value="1">APP</option>
                                <option value="2">后台</option>
                            </select>
                        </div>

                        <div class="layui-input-inline" style="margin-top: 5px">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('addPublicClass')}');">
                            <i class="fa fa-plus"></i> 添加公开课
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>

                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.public_img}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"/>
                    </script>

                    <!--状态显示模板-->
                    <script type="text/html" id="statBar">
                        {{# if(d.public_type == 1){ }}
                        免费
                        {{# } }}
                        {{# if(d.public_type == 2){ }}
                        付费
                        {{# } }}
                    </script>

                    <script type="text/html" id="statBar1">
                        {{# if(d.is_hot == 1){ }}
                        是
                        {{# } }}
                        {{# if(d.is_hot == 2){ }}
                        否
                        {{# } }}
                    </script>

                    <script type="text/html" id="statBar2">
                        {{# if(d.public_is_on == 1){ }}
                        上架中
                        {{# } }}
                        {{# if(d.public_is_on == 2){ }}
                        已下架
                        {{# } }}
                    </script>

                    <script type="text/html" id="fromBar">
                        {{# if(d.public_from == 1){ }}
                        APP
                        {{# } }}
                        {{# if(d.public_from == 2){ }}
                        后台
                        {{# } }}
                    </script>

                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.href('{:url('classDetail')}?public_id={{d.public_id}}')" class="btn btn-warning btn-xs m-r-xs" title="查看详情"><i class="fa fa-search">详情</i></a>
                        <a href="javascript:;" onclick="wk.href('{:url('sectionIndex')}?public_id={{d.public_id}}')" class="btn btn-primary btn-xs m-r-xs" title="节"><i class="fa fa-search">节</i></a>
                        {{# if(d.public_is_on == 1) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.public_id}}','{:url('classDown')}', '确定下架？')" class="btn btn-warning btn-xs m-r-xs" title="下架"><i class="fa fa-arrow-down">下架</i></a>
                        {{# } }}
                        {{# if(d.public_is_on == 2) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.public_id}}','{:url('classOn')}', '确定上架？')" class="btn btn-info btn-xs m-r-xs" title="上架"><i class="fa fa-arrow-up">上架</i></a>
                        {{# } }}
                        {{# if(d.is_hot == 1) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.public_id}}','{:url('classUnhot')}', '取消精品公开课？')" class="btn btn-warning btn-xs m-r-xs" title="取消精品公开课"><i class="fa fa-arrow-down">取消精品公开课</i></a>
                        {{# } }}
                        {{# if(d.is_hot == 2) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.public_id}}','{:url('classHot')}', '设置精品公开课？')" class="btn btn-info btn-xs m-r-xs" title="设置精品公开课"><i class="fa fa-arrow-up">设置精品公开课</i></a>
                        {{# } }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.public_id}}','{:url('classDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o">删除</i></a>
                        {{# if(d.public_is_top == 1){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.public_id}}','{:url('setClassTop')}','确定取消置顶吗?')" class="btn btn-warning btn-xs m-r-xs">取消置顶</a>
                        {{# } }}
                        {{# if(d.public_is_top == 2){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.public_id}}','{:url('setClassTop')}','确定置顶吗?')" class="btn btn-warning btn-xs m-r-xs">置顶</a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Publicclass/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
//                {type: 'checkbox', fixed: 'left',}
                {type:'numbers', width: 60, title: '序号'}
                , {field: 'public_name', width: '', title: '标题', align: 'center'}
                , {field: 'public_img', width: 90, title: '缩略图', align: 'center', templet: '#imgTpl'}
                , {field: 'subject_name', width: 90, title: '课程分类', align: 'center'}
                , {field: 'grade_name', width: 90, title: '年级', align: 'center'}
                , {field: 'public_type', width: 90, title: '是否收费', align: 'center', toolbar: '#statBar'}
                , {field: 'public_from', width: 90, title: '发布端', align: 'center', toolbar: '#fromBar'}
                , {field: 'is_hot', width: 90, title: '是否精品', align: 'center', toolbar: '#statBar1'}
                , {field: 'public_price', width: 80, title: '课程价格', align: 'center',}
                , {field: 'public_is_on', width: 100, title: '课程状态', align: 'center', toolbar: '#statBar2'}
                , {field: 'user_username', width: 100, title: '老师', align: 'center', edit: 'test'}
                , {field: 'num', width: 100, title: '报名数量', align: 'center'}
                , {fixed: 'right', width: 440, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });

        //监听单元格编辑---排序
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
            wk.change(data.banner_id,"{:url('updateSort')}",field,value);
        });

        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['lunbo_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>